package com.syni.mdd.yhd.common.all.service.impl;

import com.syni.mdd.sjb.common.component.utils.common.utils.RequestHeaderData;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsAgentDao;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsPageStatisticsDao;
import com.syni.mdd.yhd.common.all.dto.requestDto.operation.UserOperationReDto;
import com.syni.mdd.yhd.common.all.entity.BmsAgent;
import com.syni.mdd.yhd.common.all.entity.BmsPageStatistics;
import com.syni.mdd.yhd.common.all.service.BmsAgentService;
import com.syni.mdd.yhd.common.all.service.BmsPageStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @className
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class BmsPageStatisticsServiceImpl implements BmsPageStatisticsService {
    @Autowired
    BmsPageStatisticsDao bmsPageStatisticsDao;

    @Override
    public BmsPageStatisticsDao getBaseDao() {
        return bmsPageStatisticsDao;
    }

    @Override
    public void addToPageStatistics(UserOperationReDto userOperationReDto) {
        BmsPageStatistics bmsPageStatistics = new BmsPageStatistics();
        bmsPageStatistics.setStatisticsType(userOperationReDto.getOperationType());
        if(bmsPageStatistics.getStatisticsType() == null){
            bmsPageStatistics.setStatisticsType(userOperationReDto.getOperation_type());
        }
        bmsPageStatistics.setNewTime(new Date());
        bmsPageStatistics.setClient(RequestHeaderData.getRequestHeaderData().getInteger("client"));
        bmsPageStatisticsDao.save(bmsPageStatistics);
    }
}
